﻿package mortal.game.view.vip.Wing288
{
    import baseEngine.modifiers.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.systemSetting.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class Wing288Icon extends Window
    {
        private var _effectPlayer:EffectPlayer;
        private var _rect3d:Rect3DObject;
        private var _spTips:ToolTipSprite;
        private var _bmpTipsBg:GBitmap;
        private var _leftTime:SecTimerView;
        private var _guideArrow:GuideArrow;
        private var _bg2d:Img2D;
        private var _icon2d:Img2D;
        private var _txt:GTextFiled;
        private var _state:int;
        private static var _instance:Wing288Icon;

        public function Wing288Icon()
        {
            this.layer = LayerManager.entityTalkLayerParent;
            this.name = "Wing288Icon";
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = new Wing288Data();
            _loc_1.code = GameConst.TConstWingShapeCardFlyCode;
            this._spTips = UICompomentPool.getUICompoment(ToolTipSprite) as ToolTipSprite;
            this._spTips.buttonMode = true;
            this._spTips.configEventListener(MouseEvent.CLICK, this.getWing);
            this._spTips.toolTipData = _loc_1;
            this.addChild(this._spTips);
            this._bmpTipsBg = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._bmpTipsBg.width = 147;
            this._bmpTipsBg.height = 103;
            this._spTips.addChild(this._bmpTipsBg);
            var _loc_2:* = GlobalStyle.textFormatPutong.center();
            _loc_2.size = 12;
            this._txt = UIFactory.gTextField("", 0, 78, 147, 24, this, _loc_2);
            this.initRect3d();
            this.updateEffectPlayer();
            LoaderManager.instance.load(ImagesConst.funcPreViewBg + ".swf", this.winBgLoaded);
            LoaderManager.instance.load(ImagesConst.Wing288Icon + ".swf", this.iconLoaded);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResizeHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            Dispatcher.removeEventListener(EventName.StageResize, this.stageResizeHandler);
            this.removeEffect();
            EffectManager.glowFilterUnReg(this._txt);
            Rect3DManager.instance.disposeRect3d(this._rect3d);
            this._rect3d = null;
            this._txt.dispose(param1);
            this._txt = null;
            this._bmpTipsBg.dispose(param1);
            this._bmpTipsBg = null;
            this._spTips.dispose(param1);
            this._spTips = null;
            if (this._leftTime)
            {
                this._leftTime.dispose(true);
                this._leftTime = null;
            }
            this.removeArrow();
            super.disposeImpl(param1);
            return;
        }// end function

        private function removeArrow() : void
        {
            if (this._guideArrow != null)
            {
                DisplayUtil.removeMe(this._guideArrow);
                this._guideArrow.dispose(true);
                this._guideArrow = null;
            }
            return;
        }// end function

        private function getWing(event:MouseEvent) : void
        {
            var _loc_2:ItemInfo = null;
            var _loc_3:ItemData = null;
            if (this._state == 0)
            {
                _loc_2 = ItemConfig.instance.getConfig(GameConst.TConstExperWingShapeCardCode);
                MsgManager.showRollTipsMsg(_loc_2.effect + Language.getString(35598), MsgRollTipsType.msgRollTips3);
            }
            else if (this._state == 1)
            {
                GameProxy.role.getExperWingShapeCard();
            }
            else if (this._state == 2)
            {
                MsgManager.showRollTipsMsg(Language.getString(35599));
            }
            else if (this._state == 3)
            {
                _loc_3 = Cache.instance.pack.backPackCache.getItemByCode(120101173, true);
                if (_loc_3)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, _loc_3));
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(35600), MsgRollTipsType.msgRollTips3);
                }
                ClientSetting.local.setIsDone(true, IsDoneType.IsClickWing288);
                this.hide();
            }
            return;
        }// end function

        private function updateEffectPlayer() : void
        {
            var _loc_1:int = 0;
            var _loc_2:String = null;
            if (this._rect3d)
            {
                this.removeEffect();
                _loc_1 = Cache.instance.role.entityInfo.career;
                _loc_2 = "UI_test02";
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2, null, this._rect3d.renderList, false);
                this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                this._rect3d.addObject3d(this._effectPlayer, 74, 48);
                this._effectPlayer.setScale(0.8, 0.8, 0.8);
            }
            return;
        }// end function

        private function initRect3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(false, new Rectangle(0, 0, 10, 10), this);
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        private function removeEffect() : void
        {
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            return;
        }// end function

        private function iconLoaded(param1:SWFInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = param1.bitmapData;
            if (this._icon2d)
            {
                this._icon2d.dispose(false);
            }
            this._icon2d = new Img2D(null, _loc_2, new Rectangle(0, 0, _loc_2.width, _loc_2.height), true);
            this._icon2d.x = 43;
            this._icon2d.y = 25;
            this._icon2d.autoDispose = false;
            this._rect3d.addImg(this._icon2d, Layer3DManager.particleLayer);
            return;
        }// end function

        private function winBgLoaded(param1:SWFInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = param1.bitmapData;
            if (this._bg2d)
            {
                this._bg2d.dispose(false);
            }
            this._bg2d = new Img2D(null, _loc_2, new Rectangle(0, 0, _loc_2.width, _loc_2.height), true);
            this._bg2d.autoDispose = false;
            this._rect3d.addImg(this._bg2d);
            return;
        }// end function

        override protected function addCloseButton() : void
        {
            return;
        }// end function

        private function stageResizeHandler(param1) : void
        {
            this.stageResize();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.x = SceneRange.display.width - 370;
            this.y = 200;
            if (this._guideArrow)
            {
                this._guideArrow.x = this.x + this.width - 70;
                this._guideArrow.y = this.y + this.height / 2 + 35;
            }
            return;
        }// end function

        private function updateLeftTime(param1:int) : void
        {
            var _loc_2:int = 0;
            if (param1 > 0)
            {
                _loc_2 = param1;
            }
            this._leftTime.setLeftTime(_loc_2);
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 <= 0)
            {
                if (this._leftTime)
                {
                    this._leftTime.dispose();
                    this._leftTime = null;
                }
                this.updateState(3);
            }
            return;
        }// end function

        public function updateState(param1:int, param2:int = 0) : void
        {
            var _loc_3:ItemInfo = null;
            this._state = param1;
            if (param1 == 0)
            {
                _loc_3 = ItemConfig.instance.getConfig(GameConst.TConstExperWingShapeCardCode);
                this._txt.text = _loc_3.effect + Language.getString(35598);
                this._txt.x = 0;
                EffectManager.glowFilterUnReg(this._txt);
                this.removeArrow();
            }
            else if (param1 == 1)
            {
                this._txt.text = Language.getString(35601);
                this._txt.x = 0;
                EffectManager.glowFilterReg(this._txt);
                if (this._guideArrow == null)
                {
                    this._guideArrow = UICompomentPool.getUICompoment(GuideArrow) as GuideArrow;
                }
                this._guideArrow.direction = GuideArrow.Up;
                this._guideArrow.x = this.x + this.width - 70;
                this._guideArrow.y = this.y + this.height / 2 + 35;
                this._guideArrow.label = Language.getString(35601);
                LayerManager.uiLayer.addChild(this._guideArrow);
            }
            else if (param1 == 2)
            {
                this.removeArrow();
                this._txt.text = "";
                EffectManager.glowFilterUnReg(this._txt);
                if (this._leftTime == null)
                {
                    this._leftTime = UIFactory.secTimeView(Language.getString(35602) + Language.getString(35033), 32, this._txt.y, 60, 20, this, GlobalStyle.textFormatBai.center());
                    this._leftTime.filters = [FilterConst.glowFilter];
                    this._leftTime.autoSize = TextFieldAutoSize.LEFT;
                    this._leftTime.mouseEnabled = false;
                    this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
                    this.updateLeftTime(param2 + 120);
                }
            }
            else if (param1 == 3)
            {
                this.removeArrow();
                this._txt.text = Language.getString(35603);
                EffectManager.glowFilterReg(this._txt);
                if (this._guideArrow == null)
                {
                    this._guideArrow = UICompomentPool.getUICompoment(GuideArrow) as GuideArrow;
                }
                if (this._guideArrow == null)
                {
                    this._guideArrow = UICompomentPool.getUICompoment(GuideArrow) as GuideArrow;
                }
                this._guideArrow.direction = GuideArrow.Up;
                this._guideArrow.x = this.x + this.width - 70;
                this._guideArrow.y = this.y + this.height / 2 + 35;
                this._guideArrow.label = Language.getString(35603);
                LayerManager.uiLayer.addChild(this._guideArrow);
            }
            return;
        }// end function

        public static function get instance() : Wing288Icon
        {
            if (_instance == null)
            {
                _instance = new Wing288Icon;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
